package stack;

public class Bracket {
    public static String isMatched(String infix) {
        SeqStack<String> stack = new SeqStack<String>(infix.length());
        for (int i = 0; i < infix.length(); i++) {
            char ch = infix.charAt(i);
            switch (ch) {
                case '(':
                    stack.push(ch + "");
                    System.out.println(stack.toString());
                    break;

                case ')':
                    if (stack.isEmpty() || !stack.pop().equals("("))
                        return "期望(";
            }
        }
        return (stack.isEmpty()) ? "" : "期望)";
    }

    public static void main(String args[]) {
        String infix = "((1+2)*3+4))(";
        System.out.println(infix + "  ，编译错误：" + Bracket.isMatched(infix));
    }
}
